# $Id$
# Maintainer: Andreas Radke <andyrtr@archlinux.org>
# Contributor: Sergej Pupykin <sergej@aur.archlinux.org>

pkgname=man-db
pkgver=2.7.6.1
pkgrel=2
pkgdesc="A utility for reading man pages"
arch=('i686' 'x86_64')
url="http://www.nongnu.org/man-db/"
license=('GPL' 'LGPL')
groups=('base')
depends=( 'bash' 'gdbm' 'zlib' 'groff' 'libpipeline' 'less')
makedepends=('po4a')
optdepends=('gzip')
backup=('etc/man_db.conf')
conflicts=('man')
provides=('man')
replaces=('man')
install=${pkgname}.install
source=(https://download-mirror.savannah.gnu.org/releases/man-db/$pkgname-$pkgver.tar.xz{,.sig}
        convert-mans
        man-db.{timer,service})
sha256sums=('08edbc52f24aca3eebac429b5444efd48b9b90b9b84ca0ed5507e5c13ed10f3f'
            'SKIP'
            'affab3adc4b83d011ed83060d8ac579211c932e6c0900b92e12779c092ad5df3'
            '25ffaae49ecd8403df7787f988463f39821aacd35690775f1c8a2f2bf4d2bee3'
            '8cbae3f06e9847614926962b44bf68f2997365d2c5afdfbd03ad0063424f548e')
validpgpkeys=('AC0A4FF12611B6FCCF01C111393587D97D86500B') # Colin Watson <cjwatson@debian.org>

prepare() {
  cd ${pkgname}-${pkgver}

  # fix group in systemd tempfile
  sed -i 's/man\ man/root\ root/' init/systemd/man-db.conf
}

build() {
  cd ${pkgname}-${pkgver}
  ./configure --prefix=/usr \
    --sbindir=/usr/bin \
    --sysconfdir=/etc \
    --libexecdir=/usr/lib \
    --with-db=gdbm \
    --disable-setuid \
    --enable-cache-owner=root \
    --enable-mandirs=GNU \
    --with-sections="1 n l 8 3 0 2 5 4 9 6 7"
  make
}

check() {
  cd ${pkgname}-${pkgver}
  make check
}

package() {
  cd ${pkgname}-${pkgver}
  make DESTDIR=${pkgdir} install

  # part of groff pkg
  rm -f ${pkgdir}/usr/bin/zsoelim

  # script from LFS to convert manpages, see
  # http://www.linuxfromscratch.org/lfs/view/6.4/chapter06/man-db.html
  install -D -m755 ${srcdir}/convert-mans  ${pkgdir}/usr/bin/convert-mans

  # install man-db update timer
  install -D -m644 ${srcdir}/man-db.timer ${pkgdir}/usr/lib/systemd/system/man-db.timer
  install -D -m644 ${srcdir}/man-db.service ${pkgdir}/usr/lib/systemd/system/man-db.service
  install -d -m755 ${pkgdir}/usr/lib/systemd/system/multi-user.target.wants
  ln -s ../man-db.timer ${pkgdir}//usr/lib/systemd/system/multi-user.target.wants/man-db.timer
}
